<template>
  <div class="login">
      <div class="top">
        <img :src="require('../../../assets/jingwei.png')" alt="" class="logo">
        <span>精卫平台</span>
      </div>
      <div class="center">
        <img :src="require('../../../assets/banner.png')" alt="">
        <div class="login-container">
          <h2>欢迎登录</h2>
          <div class="tip">账号及密码即公司LDAP账号密码</div>
          <el-form ref="form" :model="form" :rules="rules">
            <el-form-item  prop="username">
              <el-input v-model="form.username" placeholder="OA账号"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="form.password" placeholder="密码" type="password" @keyup.native.enter="login()"></el-input>
            </el-form-item>
          </el-form>
          <el-button type="primary" class="btn" @click="login()">登录</el-button>
        </div>
      </div>
      <div class="cpright">
        智慧芽信息科技（苏州）有限公司 © 2023
      </div>
  </div>
</template>
<script>
export default {
  name: "Login",

  data() {
    return {
       rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ],
       },
      form:{
        username:'',
        password:''
      }
    };
  },

  created() {},
  methods: {
    login(){
      this.$refs['form'].validate((valid) => {
          if (valid) {
            this.$http.user.login({...this.form}).then(res => {
              
              if(res){
                  this.$cookies.set("token",res.token,60 * 60 * 12)
                  this.$cookies.set("username",this.form.username,60 * 60 * 12)
                  this.$router.push("/home")
              }
            });
          
          } else {
            return false;
          }
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.login{
  .top{
    display: flex;
    align-items: center;
    height: 80px;
    background: #fff;
    overflow: hidden;
    .logo{
      width: 55px;
      height: 55px;
      margin-left: 20px;
    }
    span{
      font-size: 26px;
      color:#626262;
      margin-left: 10px;
    }
  }
  .center{
    padding: 0 50px;
    background-image: linear-gradient(to bottom, #E8F0F5, #f3f3f3);
    height: 578px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: relative;
    img{
      width: 500px;
      height: auto;
      position: absolute;
      left: 200px;
    }
    .login-container{
      position: absolute;
      right: 200px;
      width: 350px;
      height: 400px;
      border-radius: 4px;
      background-color: #fff;
      box-sizing: border-box;
      padding: 30px;
      h2{
        text-align: center;
        font-weight: 400;
        color: #303133;
        margin: 0;
      }
      .tip{
        color: #909399;
        text-align: center;
        font-size: 13px;
        margin: 10px 0;
        margin-bottom: 35px;
      }
      .btn{
        width: 100%;
        letter-spacing: 10px!important;
        margin-top: 10px;
      }
    }
  }
  .cpright{
    background: #FFFFFF;
    line-height: 83px;
    width: 100%;
    text-align: center;
    color: #909399;
    font-size: 14px;
  }
}
</style>
